package main

import (
	"Squid/config"
	db2 "Squid/config/db"
	"Squid/models"
	"flag"
	"fmt"
	"os"
)

var (
	confFile string //配置文件路径
)


//解析命令行参数
func initArgs() {
	var (
		currentDir string
		path  string
	)

	//main -config ./config.json -xxx 123 -yyy 456
	currentDir, _ = os.Getwd()
	path = currentDir + "/config/config.json"
	flag.StringVar(&confFile, "config", path, "指定config.json")
	flag.Parse()
}

func main() {
	var (
		db  *db2.DB
		err  error
	)

	//初始化命令行
	initArgs()


	//加载配置
	if err = config.InitConfig(confFile); err != nil {
		fmt.Println("加载配置文件错误:",err.Error())
		panic(err)
	}

	db, err = db2.NewDB()
	if err != nil {
		fmt.Println("连接数据库报错：", err.Error())
		return
	}


	//fmt.Println(db.Db.Migrator().CurrentDatabase())
	if err = db.Db.AutoMigrate(&models.Job{}); err != nil {
		fmt.Println("migrate错误：", err)
		panic(err)
	}

	fmt.Println("migrate完成")

}
